package com.csdj.t309.geamtest.util;

import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.geometry.Positions;

import java.io.IOException;

public class ShearUtil {
    public static void shear(String imgPath){
        //压缩图片路径
        String smallImgPath = imgPath.replace(".", "_small.");
        try {
            //sourceRegion()指定位置
            //图片中心400*400的区域
            Thumbnails.of(imgPath)
                    .sourceRegion(Positions.CENTER,400,400)
                    .size(200,200)
                    .keepAspectRatio(false)
                    .toFile(smallImgPath);
            //图片右下400*400的区域
            Thumbnails.of(imgPath)
                    .sourceRegion(Positions.BOTTOM_RIGHT,400,400)
                    .size(200,200)
                    .keepAspectRatio(false)
                    .toFile(smallImgPath);
            //指定坐标
            Thumbnails.of(imgPath)
                    .sourceRegion(600,500,400,400)
                    .size(200,200)
                    .keepAspectRatio(false)
                    .toFile(smallImgPath);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
